//
// Created by yyancy on 2019/10/27.
//
#include <stdio.h>
#include <stdlib.h>
#include "letter.h"
//#include "delete.c"
//#include "display.c"
//#include "input.c"

int count = 20;


int menu_select(void) {
    char s[2];
    int cn = 0;
    printf("\n");
    printf("1. 输入记录\n");
    printf("2. 显示记录\n");
    printf("3. 删除记录\n");
    printf("4. 结束运行\n");
    printf("\n左边数字对应功能选择， 请选1-4: ");
    for (;;) {
        fgets(s, 2, stdin);
        while (getchar() != '\n');
        cn = atoi(s);
        if (cn < 1 || cn > 6) printf("\n输入错误， 重选1-4： ");
        else break;
    }
    return cn;
}

void handle_menu(ADDR *top) {
    for (;;) {
        switch (menu_select()) {
            case 1:
                top = input(top);
                break;
            case 2:
                display(top);
                break;
            case 3:
                top = del(top);
                break;
            case 4:
                printf("退出操作， 再见！ \n");
                exit(0);
        }
    }
}


int main() {
    ADDR *top;
    ASK(top);
    top->next = NULL;
    count = 0;
    handle_menu(top);

}
